package com.xbongbong.saas.help;

import com.xbongbong.paas.constant.PaasConstant;
import com.xbongbong.saas.domain.entity.DistributorAreaEntity;
import com.xbongbong.saas.domain.entity.ProductCategoryEntity;
import com.xbongbong.saas.model.DistributorAreaModel;
import com.xbongbong.saas.model.ProductCategoryModel;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * 经销商列表渲染辅助类
 * @author xinpeng.jiang
 * @version V1.0
 * @date 2021/1/4 19:15
 * @since V1.0
 */
@Component
public class DistributorListHelp {

    public static final Logger LOG = LoggerFactory.getLogger(DistributorListHelp.class);

    @Resource
    private DistributorAreaModel distributorAreaModel;
    @Resource
    private ProductCategoryModel productCategoryModel;

    public Map<Long,String> areaList(String corpid) {
        Map<String,Object> map = new HashMap<>(PaasConstant.DEFAULT_INITIAL_CAPACITY);
        map.put("corpid",corpid);
        map.put("del",0);
        Map<Long,String> areaMap = new HashMap<>(PaasConstant.DEFAULT_INITIAL_CAPACITY);
        List<DistributorAreaEntity> distributorAreaEntityList = distributorAreaModel.findEntities(map);
        for (DistributorAreaEntity entity : distributorAreaEntityList){
            areaMap.put(entity.getId(),entity.getName());
        }
        return areaMap;
    }

    public Map<String,Object> purchaseableGoodsList(String corpid) {
        Map<String,Object> map = new HashMap<>(PaasConstant.DEFAULT_INITIAL_CAPACITY);
        map.put("corpid",corpid);
        map.put("del",0);
        Map<String,Object> purchaseableGoodsMap = new HashMap<>(PaasConstant.DEFAULT_INITIAL_CAPACITY);
        List<ProductCategoryEntity> purchaseableGoodsList = productCategoryModel.findEntitys(map);
        for (ProductCategoryEntity entity : purchaseableGoodsList){
            purchaseableGoodsMap.put(entity.getId().toString(),entity.getName());
        }
        return purchaseableGoodsMap;
    }

}
